import Vue from 'vue'
import Router from 'vue-router'


Vue.use(Router)

const router = new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/',
      redirect: "index",
      component: () => import(/* webpackChunkName: "about" */ './views/main.vue'),
      children:[
        {
          path: '/index',
          name: 'index',
          component: () => import(/* webpackChunkName: "about" */ './views/index/index.vue')
        },
        {
          path: '/user',
          name: 'user',
          component: () => import(/* webpackChunkName: "about" */ './views/user/userManagment.vue')
        },
        {
          path: '/myInfo',
          name: 'myInfo',
          component: () => import(/* webpackChunkName: "about" */ './views/user/UserDetail.vue')
        },
        {
          path: '/sightsView',
          name: 'sightsView',
          component: () => import(/* webpackChunkName: "about" */ './views/sights/sightsView.vue')
        },
        {
          path: '/sightCheck',
          name: 'sightCheck',
          component: () => import(/* webpackChunkName: "about" */ './views/sights/sightsCheck.vue')
        },
        {
          path: '/sightsManagement',
          name: 'sightsManagement',
          component: () => import(/* webpackChunkName: "about" */ './views/sights/sightsManagement.vue')
        },

        {
          path: '/myOrder',
          name: 'myOrder',
          component: () => import(/* webpackChunkName: "about" */ './views/order/myOrder.vue')
        },
        {
          path: '/orderManagement',
          name: 'orderManagement',
          component: () => import(/* webpackChunkName: "about" */ './views/order/orderManagement.vue')
        },
        {
          path: '/myComments',
          name: 'myComments',
          component: () => import(/* webpackChunkName: "about" */ './views/comments/myComments.vue')
        },
        {
          path: '/commentsManagement',
          name: 'commentsManagement',
          component: () => import(/* webpackChunkName: "about" */ './views/comments/commentsManagement.vue')
        },
        {
          path: '/messageManagement',
          name: 'messageManagement',
          component: () => import(/* webpackChunkName: "about" */ './views/message/messageManagement.vue')
        },

        {
          path: '/messageManagement',
          name: 'messageManagement',
          component: () => import(/* webpackChunkName: "about" */ './views/message/messageManagement.vue')
        },
        {
          path: '/submitMessage',
          name: 'submitMessage',
          component: () => import(/* webpackChunkName: "about" */ './views/message/submitMessage.vue')
        },
        {
          path: '/noticeManagement',
          name: 'noticeManagement',
          component: () => import(/* webpackChunkName: "about" */ './views/notice/noticeManagement.vue')
        },
        {
          path: '/noticeView',
          name: 'noticeView',
          component: () => import(/* webpackChunkName: "about" */ './views/notice/noticeView.vue')
        },
        {
          path: '/ticketManagement',
          name: 'ticketManagement',
          component: () => import(/* webpackChunkName: "about" */ './views/ticket/ticketManagement.vue')
        },
      ]
    },
    {
      path: '/login',
      name: 'login',
      component: () => import(/* webpackChunkName: "about" */ './views/login.vue')
    },
    {
      path: '/reg',
      name: 'reg',
      component: () => import(/* webpackChunkName: "about" */ './views/register.vue')
    }
  ]
})
router.beforeEach((to, from, next) => {
  if (to.path === '/login'||to.path === '/reg') {
    next()
    return
  }
  const token = window.sessionStorage.getItem('user')
  //没有登录访问
  if (!token) {

    next('/login')
  }
  //有登录
  next();
})
export default router
